--物资调度
local wuzidiaodu = fk.CreateSkill {
    name = "mcdh_wuzidiaodu",
    tags = {Skill.Limited}
}

wuzidiaodu:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(self) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 then
            for _, move in ipairs(data) do
                if  move.from  then
                    for _, info in ipairs(move.moveInfo) do
                        if (info.fromArea == Card.PlayerHand and move.from:isKongcheng()) then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_trigger = function(self, event, target, player, data)
        local targets = {}
        local room = player.room
        for _, move in ipairs(data) do
            if move.from  then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand  and move.from:isKongcheng()  then
                        table.insertIfNeed(targets, move.from)
                    end
                end

            end
        end
        room:sortByAction(targets)
        for _, p in ipairs(targets) do
            local to = p
            if to.dead or not player:hasSkill(self) or not player:usedSkillTimes(self.name,Player.HistoryGame) == 0 then
                break
            end
            self:doCost(event, p, player, nil)
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return player.room:askForSkillInvoke(player, self.name, nil, "#mcdh_wuzidiaodu-draw:" ..target.id.."::"..target.maxHp)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = target
        to:drawCards(to.maxHp,self.name)
        player:drawCards(2,self.name)
        room:addPlayerMark(player,"#wuzidiaodu",1)
    end
})

wuzidiaodu:addEffect(fk.DrawNCards,{
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return  target == player and player:getMark("#wuzidiaodu") ~= 0
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        data.n = data.n + player:getMark("#wuzidiaodu")
    end

})

Fk:loadTranslationTable {
    ["mcdh_wuzidiaodu"] = "物资调度",
    [":mcdh_wuzidiaodu"] = "限定技,一名角色失去最后的手牌后，你可以令其摸X张牌(X为其体力上限,至多为5),然后你摸两张牌,本局游戏摸牌阶段摸牌数+1。",
    ["#mcdh_wuzidiaodu-draw"] = "物资调度:令 %src 摸 %arg 张牌",
    ["#mcdh_wuzidiaodu_buff"] = "物资调度",
}

return wuzidiaodu